package teshop.data.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@SuppressWarnings("serial")
@Entity
@Table(name = "PRODUCTS")
@NamedQueries( {
		@NamedQuery(name = "Product.findByName", query = "SELECT p FROM Product p WHERE p.name=:name"),
		@NamedQuery(name = "Product.findByDescription", query = "SELECT p FROM Product p WHERE p.description like :description") })
public class Product implements Serializable {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "PRODUCT_ID", nullable = false)
	private Long id;

	@Column(name = "NAME", nullable = false)
	private String name;

	@Column(name = "DESCRIPTION", nullable = false)
	private String description;

	@JoinColumn(name = "CATEGORY_ID", referencedColumnName = "CATEGORY_ID")
	@ManyToOne
	private Category category;

	@ManyToOne
	@JoinColumn(name = "VENDOR_VENDOR_ID", referencedColumnName = "VENDOR_ID")
	private Vendor vendor;

	@Column(name = "PRICE")
	private double price;

	@Column(name = "IMAGE_URL")
	private String imageurl;

	/** Creates a new instance of Product */
	public Product() {
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * Sets the name of this Product to the specified value.
	 * 
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the name of this Product.
	 * 
	 * @return the name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * Sets the description of this Product to the specified value.
	 * 
	 * @param description
	 *            the new description
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Gets the description of this Product.
	 * 
	 * @return the description
	 */
	public String getDescription() {
		return this.description;
	}

	/**
	 * Sets the categoryid of this Product to the specified value.
	 * 
	 * @param categoryid
	 *            the new categoryid
	 */
	public void setCategory(Category category) {
		this.category = category;
	}

	/**
	 * Gets the categoryid of this Product.
	 * 
	 * @return the categoryid
	 */
	public Category getCategory() {
		return this.category;
	}

	/**
	 * @param vendor
	 *            the vendor to set
	 */
	public void setVendor(Vendor vendor) {
		this.vendor = vendor;
	}

	/**
	 * @return the vendor
	 */
	public Vendor getVendor() {
		return vendor;
	}

	/**
	 * @param price
	 *            the price to set
	 */
	public void setPrice(double price) {
		this.price = price;
	}

	/**
	 * @return the price
	 */
	public double getPrice() {
		return price;
	}

	/**
	 * Sets the imageurl of this Product to the specified value.
	 * 
	 * @param imageurl
	 *            the new imageurl
	 */
	public void setImageurl(String imageurl) {
		this.imageurl = imageurl;
	}

	/**
	 * Gets the imageurl of this Product.
	 * 
	 * @return the imageurl
	 */
	public String getImageurl() {
		return this.imageurl;
	}

	/**
	 * Returns a hash code value for the object. This implementation computes a
	 * hash code value based on the id fields in this object.
	 * 
	 * @return a hash code value for this object.
	 */
	@Override
	public int hashCode() {
		int hash = 0;
		hash += (this.id != null ? this.id.hashCode() : 0);
		return hash;
	}

	/**
	 * Determines whether another object is equal to this Product. The result is
	 * <code>true</code> if and only if the argument is not null and is a
	 * Product object that has the same id field values as this object.
	 * 
	 * @param object
	 *            the reference object with which to compare
	 * @return <code>true</code> if this object is the same as the argument;
	 *         <code>false</code> otherwise.
	 */
	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof Product)) {
			return false;
		}
		Product other = (Product) object;
		if (this.id != other.id
				&& (this.id == null || !this.id.equals(other.id)))
			return false;
		return true;
	}

	/**
	 * Returns a string representation of the object. This implementation
	 * constructs that representation based on the id fields.
	 * 
	 * @return a string representation of the object.
	 */
	@Override
	public String toString() {
		return "com.sun.javaee.blueprints.model.Product[productid=" + id + "]";
	}
}
